<template>
  <div class="wrapper">
    <div  class="fabu_item" v-for="(applay, index) in orderDetails" :key="index" @click="goOrderDetail(applay.id)">

      <div class="applay-field" style="margin-top: 10px;">
        <span class="field-label">开始日期:</span>
        <span class="field-value">{{ applay.startDate }}</span>
      </div>
      <div class="applay-field">
        <span class="field-label">结束日期:</span>
        <span class="field-value">{{ applay.endDate }}</span>
      </div>
      <div class="applay-field">
        <span class="field-label">薪&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;酬:</span>
        <span class="field-value">{{ applay.salary }}</span>
      </div>
      <div class="applay-field">
        <span class="field-label">年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;级:</span>
        <span class="field-value">{{ applay.grade }}</span>
      </div>
      <div class="applay-field">
        <span class="field-label">科&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;目:</span>
        <span class="field-value">{{ applay.subject }}</span>
      </div>
      <div class="applay-field">
        <span class="field-label">要&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;求:</span>
        <span class="field-value">{{ applay.demand }}</span>
      </div>
      <div class="applay-field">
        <span class="field-label">城&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;市:</span>
        <span class="field-value">{{ applay.shi }}</span>
      </div>
      <div class="applay-field">
        <span class="field-label">区&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;县:</span>
        <span class="field-value">{{ applay.xian }}</span>
      </div>
      <div class="applay-field" style="margin-bottom: 10px;">
        <span class="field-label">街&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;道:</span>
        <span class="field-value">{{ applay.street }}</span>
      </div>
    </div>
  </div>
</template>
<script>
import axios from 'axios';
import settings from '../../settings.json'
import { setStatusBarColor } from "tauri-plugin-status-bar-color-api";
export default {
  components: {

  },
  data() {
    return {
      studentName: "", // 学生姓名
      tutorSubject: "", // 预约家教的科目
      appointmentTime: "", // 预约时间
      orderDetails: [], // 订单详情列表，可用于后续扩展展示历史订单等功能
      applays: [],
      user: null,
      ipAddress: settings.ipAddress
    };
  },
  created() {
    setStatusBarColor('#ffffff')
    this.user = JSON.parse(localStorage.getItem("currentUser"))
    this.getOrders()
  },
  methods: {
    async getOrders() {
      try {
        const tutor = 'tutorValue';
        const response = await axios.get(settings.ipAddress + `/order/byParentAndValid`,
          {
            params: {
              parent: this.user.username,
            }
          }
        );
        this.orderDetails = response.data;
        console.log(response.data);
      } catch (error) {
        console.error('Error selecting by tutor and start date after now:', error);
      }
    },
    showUser(name) {
      this.isShowUser = 1
      this.$router.push({ path: '/user', query: { username: name } })
    },
    async deleteByTutorAndId(id) {
      try {
        const response = await axios.delete(settings.ipAddress + `/applay/deleteByTutorAndId?id=${id}&tutor=${this.user.username}`);
        alert("取消成功")
        this.selectByTutorAndStartDateAfterNow()
      } catch (error) {
        console.error('Error deleting by tutor and id:', error);
      }
    },
    goOrderDetail(id) {
      this.$router.push({ path: '/orderDetail', query: { id: id } })
    }

  }
};
</script>
<style lang="scss" scoped>
$primary-color: #ffffff;
$secondary-color: #E8F5E9;
$text-color: #333;
$border-color: #C8E6C9;

.wrapper {
  width: 100vw;
  height: calc(100vh - 70px);
  position: fixed;
  top: 70px;
  background-color: #dee6d8;

  .fabu_item {
    padding-top: 5px;
    padding-bottom: 5px;
    border-bottom: 1px solid $border-color;
    width: 90vw;
    height: fit-content;
    margin-top: 10px;
    margin-left: 5vw;
    margin-bottom: 10px;
    background-color: #ffffff;
    border-radius: 4px;

    &:last-child {
      border-bottom: none;
    }

    .applay-field {
      span {
        border-bottom: 0.1px solid #000;
      }

      // background-color: #f32929;
      display: flex;
      flex-wrap: wrap;
      margin-top: 5px;
      margin-bottom: 5px;
      width: 84vw;
      max-width: 84vw;
      margin-left: 3vw;

      .field-label {
        flex: 0 0 30%;
        font-weight: bold;
        font-size: 13px;
        color: $text-color;
      }

      .field-value {
        flex: 0 0 70%;
        font-size: 13px;
        color: $text-color;
      }

      .but {
        margin-left: 30vw;
        width: 24vw;
        height: 24px;
        font-size: 14px;
        line-height: 24px;
        text-align: center;
        border-radius: 2px;
        color: #ffffff;
        margin-bottom: 5px;
        background-color: #fb0202;
      }
    }
  }
}
</style>